//
//  PersonalVipCell.m
//  ChatForHot
//
//  Created by wr on 2018/10/11.
//  Copyright © 2018年 FLY. All rights reserved.
//

#import "PersonalVipCell.h"
#import "PersonalVipCellModel.h"

@interface PersonalVipCell ()

@property (nonatomic, strong) UIImageView *HOTCHATmarkIcon;
@property (nonatomic, strong) YYLabel *HOTCHATtitleLabel;
@end

@implementation PersonalVipCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self HOTCHATinitSubViews];
    }
    return self;
}

- (void)HOTCHATinitSubViews {
    self.HOTCHATmarkIcon = [[UIImageView alloc] init];
    [self.contentView addSubview:self.HOTCHATmarkIcon];
    [self.HOTCHATtitleLabel setFont:[UIFont systemFontOfSize:16]];
    self.HOTCHATtitleLabel = [[YYLabel alloc] init];
    [self.HOTCHATtitleLabel setTextColor:[UIColor colorFromHexString:@"#0092FF"]];
    self.HOTCHATtitleLabel.backgroundColor = [UIColor clearColor];
    self.HOTCHATtitleLabel.textAlignment = NSTextAlignmentCenter;
    self.HOTCHATtitleLabel.numberOfLines = 0;
    [self.contentView addSubview:self.HOTCHATtitleLabel];
}

- (void)layoutSubviews {
    [super layoutSubviews];

    self.HOTCHATmarkIcon.size = CGSizeMake(8, 8);
    self.HOTCHATmarkIcon.top = 10;
    self.HOTCHATmarkIcon.left = 15;
    
    if (self.model.tag > 13 && self.model.tag < 16) {
        self.HOTCHATtitleLabel.size = CGSizeMake(self.model.titleTextLayout.textBoundingSize.width + 150, self.model.titleTextLayout.textBoundingSize.height);
    }else {
     self.HOTCHATtitleLabel.size = self.model.titleTextLayout.textBoundingSize;
    }
    
    self.HOTCHATtitleLabel.left = self.HOTCHATmarkIcon.right + 30;
    self.HOTCHATtitleLabel.top = 10;
}

- (void)HOTCHATbind:(PersonalVipCellModel *)model {
    _model = model;
    
    [self.HOTCHATmarkIcon setImage:[UIImage imageNamed:model.icon]];
    
    if (self.model.tag > 13 && self.model.tag < 16) {
        NSString *mmstr = [NSString stringWithFormat:@"%@%@",NSLocalizedString(@"personalVIP_helpTip", nil),model.title];
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:mmstr];
        NSRange strRange = [mmstr rangeOfString:model.title];//{0,[str length]};
        [str addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:strRange];
        UIColor *bluecolor = [UIColor blueColor];
        [str addAttribute:NSForegroundColorAttributeName value:bluecolor range:strRange];
        self.HOTCHATtitleLabel.attributedText = str;
    }else {
        self.HOTCHATtitleLabel.attributedText = self.model.titleTextLayout.text;
    }
}
 @end
